import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.*;

/**
 * This is the visual element of the map, that goes in the HUD
 *
 */

public class Map extends JPanel{

	Image map;
	//JPanel main;
	JLabel dotLabel;
	Point[] listOfPoints;
	int currentPoint = 0;
	
	/**
	 * creates list of points, loads images, and assembles the map panel
	 */
	public Map(){
		listOfPoints = new Point[17];
		listOfPoints[0] = new Point(80, 13);
		listOfPoints[1] = new Point(85, 20);
		listOfPoints[2] = new Point(90, 25);
		listOfPoints[3] = new Point(114, 80);
		listOfPoints[4] = new Point(122, 86);
		listOfPoints[5] = new Point(128, 90);
		listOfPoints[6] = new Point(125, 94);
		listOfPoints[7] = new Point(130, 90);
		listOfPoints[8] = new Point(96, 110);
		listOfPoints[9] = new Point(75, 123);
		listOfPoints[10] = new Point(75, 123);
		listOfPoints[11] = new Point(75, 123);
		listOfPoints[12] = new Point(75, 123);
		listOfPoints[13] = new Point(75, 123);
		listOfPoints[14] = new Point(75, 123);
		listOfPoints[15] = new Point(75, 123);
		listOfPoints[16] = new Point(75, 123);
		
		
		
		//main = new JPanel();
		BufferedImage map = new BufferedImage(1, 1, 1);
	        try
	        {
	            map = ImageIO.read(new File("map2small.png"));
	        }
	        catch (IOException e)
	        {
	            // TODO Auto-generated catch block
	            e.printStackTrace();
	        }
        JLabel picLabel = new JLabel(new ImageIcon( map ));
        
        BufferedImage dot = new BufferedImage(1, 1, 1);
        try
        {
            map = ImageIO.read(new File("dot.png"));
        }
        catch (IOException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        dotLabel = new JLabel(new ImageIcon(dot));
        
        this.setPreferredSize(new Dimension(147, 132));
        
        
        
    	dotLabel.setLocation(listOfPoints[currentPoint]);
    	//main.setLayout(new FlowLayout());
    	JPanel dotPanel = new JPanel();
    	dotPanel.setPreferredSize(new Dimension(21, 20));
    	dotPanel.add(dotLabel);
    	
    	JPanel mapPanel = new JPanel();
    	mapPanel.add(picLabel);
      	
       // add(mapPanel);
        //add(dotPanel);
   
	}
	
	/**
	 * Draws the points on the map
	 */
	public void paintComponent(Graphics g){
		
		super.paintComponent(g);
		
		try
        {
            g.drawImage(ImageIO.read(new File("map5small.png")), 0, 0, null);
        }
        catch (IOException e)       {e.printStackTrace();}
        
        g.setColor(Color.yellow);
        try{
        	g.fillOval(listOfPoints[currentPoint].x, listOfPoints[currentPoint].y, 10, 10);
        	//currentPoint++;
        }
        catch (ArrayIndexOutOfBoundsException e){
        	
        }
        
	/*	   try
	        {
	            g.drawImage(ImageIO.read(new File("map_small.png")), 0, 0, null);
	        }
	        catch (IOException e)       {e.printStackTrace();}
		g.fillOval(listOfPoints[currentPoint].x, listOfPoints[currentPoint].y, 15, 15);
		currentPoint++;
		*/
	}
	/**
	 * Getter for the map panel
	 * @return JPanel map
	 */
	public JPanel getMap(){
		return this;
	}
	
	/**
	 * increments the position of the game piece 
	 */
	public void movePosition(){
		currentPoint++;

		Point p = listOfPoints[currentPoint];
		
		//dotLabel.setLocation(p);
	}
	
}
